// 
//  Copyright 2011  reda
// 
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
// 
//        http://www.apache.org/licenses/LICENSE-2.0
// 
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
using System;
using ManiacMusicManager.Data.Exceptions;
using NHibernate;
namespace ManiacMusicManager.Data
{
	public partial class SessionManager : IDisposable
	{
		#region Constructeur
		private SessionManager (string dbFileName)
		{
			this._lock				= new object();
			this._dbFileName		= dbFileName;
			this.IsAccessible		= true;
			this._sessionFactory	= this.CreateSessionFactory(); // Ne pas changer l'ordre des 2 dernieres instructions, sinon ça ne marche plus
		}
		#endregion
		
		#region Champs privés
		private readonly string _dbFileName;
		private readonly ISessionFactory _sessionFactory;
		#endregion
		
		#region propriétés
		/// <summary>
		/// Chemin de fichier base de données
		/// </summary>
		public string DbFileName {
			get {
				if(! this.IsAccessible)
					throw new InvalidSessionException();
				return this._dbFileName;
			}
		}

		/// <summary>
		/// Retourne la session factory
		/// </summary>
		public ISessionFactory Factory {
			get {
				if(! this.IsAccessible)
					throw new InvalidSessionException();
				return this._sessionFactory;
			}
		}
		
		/// <summary>
		/// Indique si une instance de session manager est toujours valide et utilisable
		/// </summary>
		public bool IsAccessible {
			get;
			private set;
		}
		#endregion
	}
}

